using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Acms.SqlDal;

namespace Acms.Bll
{
    public class ControlType : BaseItem
    {
        private ControlType() : base() { }
        private ControlType(Hashtable table) : base(table) { }
        private ControlType(Hashtable table, List<ControlType> collection) : base(table, collection) { }

        protected override Base CreateDal()
        {
            return new ControlTypeDal();
        }

        public static ControlType CreateInstance()
        {
            return new ControlType();
        }

        private static ControlType GetItem(Hashtable table)
        {
            if (table != null)
                return new ControlType(table);
            else
                return null;
        }

        private static List<ControlType> GetItems(Hashtable[] tables)
        {
            if (tables != null)
            {
                List<ControlType> tmp = new List<ControlType>();
                foreach (Hashtable table in tables)
                {
                    tmp.Add(new ControlType(table, tmp));
                }
                return tmp;
            }
            else
            {
                return null;
            }
        }

        public static ControlType GetById(int id)
        {
            ControlTypeDal dal = new ControlTypeDal();
            return GetItem(dal.GetById(id));
        }

        public static List<ControlType> GetAllBySiteId(int siteId)
        {
            ControlTypeDal dal = new ControlTypeDal();
            return GetItems(dal.GetAllBySiteId(siteId));
        }

        protected override void Load(Hashtable table)
        {
            id = (int)table[ControlTypeDal.Fields.Id];
            siteId = (int?)table[ControlTypeDal.Fields.SiteId];
            name = (string)table[ControlTypeDal.Fields.Name];
            adminControlType = (string)table[ControlTypeDal.Fields.AdminControlType];
            searchXPath = (string)table[ControlTypeDal.Fields.SearchXPath];
            custom = (bool)table[ControlTypeDal.Fields.Custom];
        }

        private int id;
        public int Id
        {
            get { return id; }
        }

        private int? siteId;
        public int? SiteId
        {
            get { return siteId; }
            set { siteId = value; }
        }

        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private string adminControlType;
        public string AdminControlType
        {
            get { return adminControlType; }
            set { adminControlType = value; }
        }

        private string searchXPath;
        public string SearchXPath
        {
            get { return searchXPath; }
            set { searchXPath = value; }
        }

        private bool custom;
        public bool Custom
        {
            get { return custom; }
            set { custom = value; }
        }

         public new void Update()
        {
            base.Update();
        }

        public new void Delete()
        {
            base.Delete();
        }

        protected override void SaveChanges(ref object concurencyId, Base dal)
        {
            ((ControlTypeDal)dal).Update(ref id, siteId, name, adminControlType, searchXPath, custom, ref concurencyId);
        }

        protected override void DeleteRecord(object concurencyId, Base dal)
        {
            ((ControlTypeDal)dal).Delete(id, concurencyId);
        }
    }
}
